<?php

use app\assets\ApiAsset;
use app\assets\LayerAsset;
use app\assets\TableAsset;
use app\models\KeyMap;
use app\models\UserCardRecharge;
use app\widgets\LinkPager;
use app\widgets\ManagerTableOp;
use yii\helpers\Html;
use yii\helpers\Url;
use dosamigos\datepicker\DatePicker;
/**
 * @var $this yii\web\View
 * @var $pagination yii\data\Pagination
 */

ApiAsset::register($this);
LayerAsset::register($this);
TableAsset::register($this);

$this->title = '等待激活卡列表';
$this->params['breadcrumbs'][] = '系统统计';
$this->params['breadcrumbs'][] = $this->title;
?>

<table class="table table-striped table-bordered table-hover">
    <thead>
    <tr>
        <th class="center">
            <label class="pos-rel">
                <input type="checkbox" class="ace" />
                <span class="lbl">编号</span>
            </label>
        </th>
        <th class="center">代理商</th>
        <th class="center">ICCID</th>
        <th class="center">套餐</th>
        <th class="center">时长</th>
        <th class="center">充值金额</th>
        <th class="center">交易单号</th>
        <th class="center">来源</th>
        <th class="center">充值类型</th>
        <th class="center">激活状态</th>
        <th class="center">失败次数</th>
        <th class="center">创建时间</th>
        <th class="center">操作</th>
    </tr>
    </thead>
    <tbody>
    <?php foreach ($waitList as $wait) {?>
        <tr>
            <td class="center"><label class="pos-rel"><input type="checkbox" class="ace" value="<?php echo $wait->id;?>" /><span class="lbl"><?php echo $wait->id;?></span></label></td>
            <td class="center"><?php echo $wait->agent->username;?></td>
            <td class="center"><?php echo $wait->iccid;?></td>
            <td class="center"><?php echo $wait->package->name;?></td>
            <td class="center"><?php echo $wait->term_length;?></td>
            <td class="center"><?php echo sprintf("%.2f",$wait->price);?></td>
            <td class="center"><?php echo $wait->trade_no;?></td>
            <td class="center"><?php echo KeyMap::getValue('source',$wait->source);?></td>
            <td class="center"><?php echo KeyMap::getValue('length_unit',$wait->length_unit);?></td>
            <td class="center">
                <?php
                    if($wait->is_refresh == 1){
                        echo '已激活';
                    }else{
                        echo '未激活';
                    }
                ?>
            </td>
            <td class="center"><?php echo $wait->fail_number;?></td>
            <td class="center"><?php echo Yii::$app->formatter->asDatetime($wait->create_time);?></td>
            <td class="center">
            <?php echo ManagerTableOp::widget(['items' => [
                    ['icon' => 'fa fa-info-circle', 'href' => Url::to(['/admin/finance/recharge-view', 'id' => $wait->recharge_id]), 'btn_class' => 'btn btn-xs btn-default', 'tip' => '详情'],
                    ['icon' => 'fa fa-hourglass-start', 'onclick' => 'resetFail('.$wait->id.')', 'btn_class' => 'btn btn-xs btn-success','tip' => '重置', 'color'=>'green'],
                    ['icon' => 'fa fa-trash', 'onclick' => 'deleteLog('.$wait->id.')', 'btn_class' => 'btn btn-xs btn-danger','tip' => '删除', 'color'=>'red']
                ]]);?>
            </td>
        </tr>
    <?php }?>
    </tbody>
</table>
<?php echo LinkPager::widget(['pagination' => $pagination]);?>
<script>
    function resetFail(id) {
        if (!confirm('确定要重置失败次数吗？')) {
            return false;
        }
        $.getJSON('<?php echo Url::to(['/admin/analyse/reset-fail']);?>', {'id':id}, function(json) {
            if(json.code == "1"){
                 layer.msg(json.msg, function () {window.location.reload();});
               }else{
                   layer.msg(json.msg);
               }
        });
    }
    function deleteLog(id) {
        if (!confirm('确定要删除吗？')) {
            return false;
        }
        $.getJSON('<?php echo Url::to(['/admin/analyse/delete-wait-active']);?>', {'id':id}, function(json) {
            if (callback(json)) {
                layer.msg('删除成功', function () {window.location.reload();});
            }
        });
    }

</script>
